package com.own.business.log.operation.persistence.entity.bo;

import com.own.business.log.operation.persistence.entity.po.LogOperation;
import com.own.component.common.base.entity.BaseBo;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * LogOperationBo
 *
 * @author chenxueli
 * @date 2023-08-09 10:24:19
 */
@Schema(title = "操作日志持久化" + ConstantBeanSuffix.BO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class LogOperationBo extends BaseBo<LogOperation> implements Serializable {

    @Schema(title = "操作编码")
    private String code;

    @Schema(title = "响应信息")
    private String message;

    @Schema(title = "登录令牌")
    private String token;

    @Schema(title = "用户id")
    private Long userId;

    @Schema(title = "用户名")
    private String userName;

    @Schema(title = "状态 1=成功 2=失败")
    private Integer status;

    @Schema(title = "方法名（全限定名）")
    private String methodName;

    @Schema(title = "客户端")
    private String client;

    @Schema(title = "ip")
    private String ip;

    @Schema(title = "模块名称")
    private String moduleName;

    @Schema(title = "操作名称")
    private String operationName;

    @Schema(title = "请求时间")
    private LocalDateTime requestTime;

    @Schema(title = "请求参数")
    private String requestParams;

    @Schema(title = "响应时间")
    private LocalDateTime responseTime;

    @Schema(title = "响应参数")
    private String responseParams;

    @Schema(title = "链路id")
    private String traceId;

    @Schema(title = "等级")
    private Integer level;

    /**
     * 转持久化对象
     *
     * @param entity 原持久化对象
     * @return 持久化对象
     */
    @Override
    public LogOperation toPo(LogOperation entity) {
        if (entity == null) {
            entity = new LogOperation();
        }
        entity.setCode(this.code);
        entity.setMessage(this.message);
        entity.setToken(this.token);
        entity.setFkUserId(this.userId);
        entity.setUserName(this.userName);
        entity.setStatus(this.status);
        entity.setMethodName(this.methodName);
        entity.setClient(this.client);
        entity.setIp(this.ip);
        entity.setModuleName(this.moduleName);
        entity.setOperationName(this.operationName);
        entity.setRequestTime(this.requestTime);
        entity.setRequestParams(this.requestParams);
        entity.setResponseTime(this.responseTime);
        entity.setResponseParams(this.responseParams);
        entity.setTraceId(this.traceId);
        entity.setLevel(this.level);
        return super.toPo(entity);
    }

}

